#include "LinkStack.h"
#include <stdio.h>
#include <stdlib.h>

struct LinkStack
{
    DLlist list;
};

LStack *InitLinkStack()
{
    LStack *s = (LStack*)malloc(sizeof(LStack));
    if(s == NULL)
        return NULL;
    InitDLlist(&s->list);
    return s;
}

void LSPush(LStack *s,ElementType element)
{
     InsertTail(&s->list,element);
}

void LPop(LStack *s)
{
    RemoveByIndex(&s->list,s->list.len - 1,NULL);
}

ElementType *GetSTop(LStack *s)
{
    if(s->list.len == 0)
        return NULL;
    return &s->list.tail->data;
}

bool IsStackEmpty(LStack *s)
{
    return s->list.len == 0;
}

void TravelLStack(LStack *s, void (*funcPtr)(ElementType))
{
    Travel(&s->list,funcPtr);
}

void ClearLStack(LStack *s, void (*clearPtr)(ElementType))
{
    ClearDLlist(&s->list,clearPtr);
}

int GetStackLen(LStack *s)
{
    return s->list.len;
}
